package Object.net.tjdz.view;

import Object.net.tjdz.service.StudentService;
import Object.net.tjdz.service.TeacherService;
import java.util.Scanner;

public class MainApp {
    private final Scanner scanner = new Scanner(System.in);
    private final StudentUI studentUI;
    private final TeacherUI teacherUI;

    public MainApp() {
        // 初始化服务层
        StudentService studentService = new StudentService();
        TeacherService teacherService = new TeacherService();

        // 初始化UI层
        this.studentUI = new StudentUI(studentService);
        this.teacherUI = new TeacherUI(teacherService);
    }

    public void start() {
        while (true) {
            System.out.println("\n=== 学校信息管理系统 ===");
            System.out.println("1. 学生信息管理");
            System.out.println("2. 教师信息管理");
            System.out.println("0. 退出系统");
            System.out.print("请选择：");

            int choice = getIntInput();

            switch (choice) {
                case 1 -> studentUI.showMenu();
                case 2 -> teacherUI.showMenu();
                case 0 -> {
                    System.out.println("感谢使用，再见！");
                    System.exit(0);
                }
                default -> System.out.println("无效输入，请重新选择！");
            }
        }
    }

    private int getIntInput() {
        while (!scanner.hasNextInt()) {
            System.out.print("请输入数字：");
            scanner.next();
        }
        return scanner.nextInt();
    }

    public static void main(String[] args) {
        new MainApp().start();
    }
}